<script>
import outMain from "@/components/outMain.vue";
import interviewForm from "@/views/modules/interviewForm.vue";

import { ElMessage, ElMessageBox } from "element-plus";
import { PositionDeliver, inviteInterview, checkReadStatus } from "@/http/api";

export default {
  components: { outMain, interviewForm },
  name: "",
  data() {
    return {
      tableData: [],
      showInterview: false,
      interviewId: "",
      statusArr: [
        { label: "全部", value: "" },
        { label: "已读", value: "2" },
        { label: "未读", value: "1" },
      ],
      queryData: {
        position_name: "",
        is_read: "",
        real_name: "",
        page: 1,
        per_page: 20,
      },
      total: 0,
    };
  },
  props: {},
  setup() {},
  methods: {
    linkFn(url, id, navId) {
      console.log(id);
      if (id != 0) {
        this.$router.push({ path: url, query: { id: id, navId: navId } });
      }
    },
    exportFn(row) {
      this.$router.push({
        path: "/salaExport",
        query: { id: row.biographical_notes_id },
      });
    },
    checkStatus(row, type) {
      ElMessageBox.confirm(`确定标记此投递简历为已读状态吗?`, "操作提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        let data = {
          user_position_deliver_id: row.user_position_deliver_id,
          status: type,
        };
        checkReadStatus(data).then((res) => {
          if (res.data.code == 1) {
            ElMessage({
              type: "success",
              message: "操作成功",
            });
            this.getData();
          }
        });
      });
    },
    async sureInterview(formData) {
      const { data } = await inviteInterview(formData);
      if (data.code == 1) {
        ElMessage({
          type: "success",
          message: "邀请成功",
        });
        this.getData();
        this.showInterview = false;
      }
    },
    interviewFn(row) {
      this.interviewId = row.biographical_notes_id;
      this.showInterview = true;
    },
    detailFn(id) {
      this.$router.push({
        path: "/workListDetail",
        query: { id: id, page: this.queryData.page },
      });
    },
    async getData() {
      const { data } = await PositionDeliver(this.queryData);
      if (data.code == 1) {
        this.tableData = data.data.data;
        this.total = data.data.total;
      }
    },
  },
  mounted() {},
  created() {
    this.queryData.page = Number(localStorage.getItem("boot_page")) || 1;

    this.getData();
  },
};
</script>
<template>
  <outMain>
    <div class="tableCont">
      <div class="tableName flexCont">
        <div>投递记录（{{ total }}）</div>
      </div>
      <div class="tableSerch">
        <div class="serchLeft"></div>
        <div class="serchRight">
          <el-form class="flexCenter" :inline="true">
            <el-form-item>
              <el-input
                clearable
                @clear="getData"
                @keyup.enter="getData"
                v-model="queryData.watercraft_name"
                placeholder="请输入船舶名称"
              />
            </el-form-item>
            <el-form-item>
              <el-input
                clearable
                @clear="getData"
                @keyup.enter="getData"
                v-model="queryData.position_name"
                placeholder="请输入岗位职务"
              />
            </el-form-item>
            <el-form-item>
              <el-input
                clearable
                @clear="getData"
                @keyup.enter="getData"
                v-model="queryData.real_name"
                placeholder="请输入投递船员姓名"
              />
            </el-form-item>
            <el-form-item>
              <el-select
                v-model="queryData.is_read"
                clearable
                @change="getData"
                placeholder="请选择投递处理状态"
              >
                <el-option
                  v-for="item in statusArr"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
            <btn value="搜索" @ok="getData"></btn>
          </el-form>
        </div>
      </div>
      <el-table class="tableMain" :data="tableData" stripe style="width: 100%">
        <el-table-column
          prop="position_name"
          show-overflow-tooltip
          label="投递岗位"
        />
        <el-table-column
          prop="watercraft_name"
          show-overflow-tooltip
          label="投递船舶"
        />
        <el-table-column
          prop="real_name"
          width="80"
          show-overflow-tooltip
          label="投递船员"
        >
          <template #default="{ row }">
            <span
              class="linkText_"
              @click="linkFn('salaPublicDetail', row.biographical_notes_id)"
            >
              {{ row.real_name }}
            </span>
          </template>
        </el-table-column>
        <el-table-column
          prop="mobile"
          width="120"
          show-overflow-tooltip
          label="手机号"
        />
        <el-table-column
          prop="gzjy"
          width="80"
          show-overflow-tooltip
          label="工作经验"
        >
          <template #default="{ row }">{{ row.gzjy }}年</template>
        </el-table-column>
        <el-table-column
          width="80"
          prop="xl"
          show-overflow-tooltip
          label="船员学历"
        />
        <el-table-column
          width="80"
          prop="zs"
          show-overflow-tooltip
          label="证书等级"
        />
        <el-table-column
          width="80"
          prop="cblx"
          show-overflow-tooltip
          label="船舶类型"
        />
        <el-table-column prop="qwyx" show-overflow-tooltip label="期望薪资">
          <template #default="{ row }">${{ row.qwyx }}</template>
        </el-table-column>
        <el-table-column width="80" show-overflow-tooltip label="处理状态">
          <template #default="{ row }">
            <div class="tagGroup">
              <el-tag v-if="row.is_read === 1">未读</el-tag>
              <el-tag type="info" v-if="row.is_read === 2">已读</el-tag>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="create_time"
          width="180"
          show-overflow-tooltip
          label="投递时间"
        />
        <el-table-column prop="Name" width="220" label="操作">
          <template #default="{ row }">
            <div class="tableCtrl">
              <div
                class="greenText ctrlText"
                @click="detailFn(row.enterprise_position_id)"
              >
                详情
              </div>
              <div class="greenText ctrlText" @click="interviewFn(row)">
                邀面试
              </div>
              <div
                class="blueText ctrlText"
                v-if="row.is_read == 1"
                @click="checkStatus(row, 2)"
              >
                标已读
              </div>
              <div class="blueText ctrlText" @click="exportFn(row)">
                导出简历
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="pageCont">
        <el-pagination
          v-model:currentPage="queryData.page"
          v-model:page-size="queryData.per_page"
          background
          layout="total, prev, pager, next, jumper"
          :total="total"
          @size-change="getData"
          @current-change="getData"
        />
      </div>
      <el-dialog v-model="showInterview" title="邀请面试" width="600">
        <interviewForm
          @cancel="showInterview = false"
          @ok="sureInterview"
          :interviewId="interviewId"
        ></interviewForm>
      </el-dialog>
    </div>
  </outMain>
</template>
<style scoped lang="less"></style>
